package repository

import (
	"database/sql/driver"
	"encoding/json"
	"gorm.io/gorm"
	"time"
)

type GormList []string

// Value 处理Value
func (g GormList) Value() (driver.Value, error) {
	return json.Marshal(g)
}

// Scan 实现 sql.Scanner 接口，Scan 将 value 扫描至 Jsonb
func (g *GormList) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), &g)
}

type BaseModel struct {
	ID        int32          `gorm:"primarykey;type:int" json:"id"`
	CreatedAt time.Time      `gorm:"column:create_time" json:"create_time"`
	UpdatedAt time.Time      `gorm:"column:update_time" json:"update_time"`
	DeletedAt gorm.DeletedAt `gorm:"column:update_time" json:"delete_time"`
	IsDeleted bool           `gorm:"column:is_deleted" json:"is_deleted"`
}
